<layout name='Layout/layout_popup' />
<script type="text/javascript" src="__PUBLIC__/js/jquery-ui.min.js"></script>
<script type="text/javascript">
	function save() {
		$("#dept_wrap", parent.document).hide();
		$("#dept_wrap", parent.document).html("");

		$("#rc select option").each(function(i) {
			//email=($(this).html().split(";")[1].split("&")[0]);
			$("#dept_wrap", parent.document).append('<span  emp_no="' + $(this).val() + '">' + jQuery.trim($(this).text()) + ' </span>');
		});

		$("#dept_wrap span b", parent.document).each(function() {
			$(this).remove();
		})

		$("#dept_wrap span", parent.document).each(function() {
			$(this).append("<b>;</b>   ");
		})
		$("#dept_wrap span", parent.document).last().find("b").remove();

		$("#dept_wrap", parent.document).show();

		myclose();
	}


	$(document).ready(function() {

		$("#dept .tree_menu  a").click(function() {//点击节点时读取相应的数据
			$("#dept .tree_menu a").removeClass("active");
			$(this).attr("class", "active");
			return false;
			//禁止连接生效
		});

		$("#dept .tree_menu  a").dblclick(function() {//点击节点时读取相应的数据
			$("#dept .tree_menu a").removeClass("active");
			$(this).attr("class", "active");
			add_address('rc');
			return false;
			//禁止连接生效
		});

		$("#rc  select").live("dblclick", function() {// 双击添加到收件人 因后添加的数据 所以需要用live函数
			$(this).find("option:selected").remove();
			$("#rc_count").text("(" + $("#rc select option").length + ")");
		});

		$("#rc select").droppable({
			activeClass : "ui-state-default",
			hoverClass : "ui-state-hover",
			accept : ":not(.ui-sortable-helper)",
			drop : function(event, ui) {
				$text = ui.draggable.text();
				$val = ui.draggable.find("input").val();
				if ($("#rc select option[value='" + $val + "']").val() == undefined) {
					$option = $("<option></option>");
					$option.val($val);
					$option.text($text).appendTo(this);
					$("#rc_count").text("(" + $("#rc select option").length + ")");
				};
			},
		}).sortable({
			items : "option:not(.placeholder)",
			sort : function() {
				// gets added unintentionally by droppable interacting with sortable
				// using connectWithSortable fixes this, but doesn't allow you to customize active/hoverClass options
				$(this).removeClass("ui-state-default");
			}
		});

	})
	//最终确认

	function add_address(name) {
		$dept_id = $("#dept a.active").attr("node");
		$dept_name = $("#dept a.active span").text();

		if ($dept_id == undefined) {
			alert("请选择部门");
			return false;
		}
		$text = $dept_name;
		$val = "dept_" + $dept_id;
		if ($("#" + name + " select option[value='" + $val + "']").val() == undefined) {
			$option = $("<option></option>");
			$option.val($val);
			$option.text($text).appendTo("#" + name + " select");
			$("#" + name + "_count").text("(" + $("#" + name + " select option").length + ")");
		};
	}

	//-->
</script>
<div class="title panel panel-default">
<div class="panel-body">
	<span>选择部门</span>
</div>
<div class="operate panel panel-default">	<div class="panel-body">
	<span class="left">双击可以添加和删除对应的节点</span>
	<div class="pull-right">
		<a  onclick="save();" class="btn btn-default">确定</a>
		<a  onclick="myclose();" class="btn btn-default">关闭</a>
	</div>
</div></div>
<div class="row">
	<div class="col-md-6">
		<div class="row form-horizontal">
			<div class="form-group">
				<b>部门</b>
			</div>
		</div>
		<div class="row popup_tree_menu"  style="height:403px;">
			<div id="dept" style="width:100%;height:100%;" class="dp dept">
				{$list_dept}
			</div>
		</div>
	</div>
	<div class="col-md-6" >
		<div class="row form-horizontal">
			<div class="form-group">
				<b>已选</b>
				<span id="rc_count"></span>
			</div>
		</div>
		<div class="row form-horizontal" >
			<div class="form-group">
				<div id="rc" style="width:100%;height:413px;overflow:hidden">
					<select size="6" style="height:100%;width:100%;"></select>
				</div>
			</div>
		</div>
	</div>
</div>